# coding:utf-8
"""
description:Ceiling light和3，5kw high power switch setting 页面
"""
import os
import random

from appium.webdriver.common import mobileby

from common.Get_Yaml import get_yaml
from config.GlobalParameter import TEST_Element_YAML
from pages.Dashboard_page import dashboard_page

Switch_Data = get_yaml(os.path.join(TEST_Element_YAML, 'Devices', '35kwPlugCeiling.yaml'))


class kwPlugCeiling_page(dashboard_page):
    by = mobileby.MobileBy()

    """ Ceiling Light》Device Setting》Light status一行"""
    SettingsSaveState_loc = (by.ID, Switch_Data.get_elementInfo(0))

    def gettext_SettingsSaveState(self):
        """获取2 way switch Connected开关按钮"""
        return self.find_element(*self.SettingsSaveState_loc).text

    def click_SettingsSaveState(self):
        """Ceiling Light》Device Setting》点击Light status一行"""
        self.find_element(*self.SettingsSaveState_loc).click()

    # Ceiling Light》Device Setting》Light status弹框的第一个default选项（Close popup）
    btnSaveStateDefault_loc = (by.ID, Switch_Data.get_elementInfo(1))

    def click_btnSaveStateDefault(self):
        """Ceiling Light》Device Setting》Light status弹框的第一个default选项（Close popup）"""
        self.find_element(*self.btnSaveStateDefault_loc).click()

    # Ceiling Light》Device Setting》Light status弹框的第而个remember选项
    btnSaveStateRemember_loc = (by.ID, Switch_Data.get_elementInfo(2))

    def click_btnSaveStateRemember(self):
        """Ceiling Light》Device Setting》Light status弹框的第而个remember选项"""
        self.find_element(*self.btnSaveStateRemember_loc).click()

    def func_LightStatus(self, message):
        """
        随机切换User Behavior》Light Status》default和remember状态
        :param message: 断言内容
        """
        self.click_SettingsSaveState()
        if random.randint(1, 2) == 1:
            self.click_btnSaveStateDefault()
            return message[0] in self.gettext_SettingsSaveState()
        else:
            self.click_btnSaveStateRemember()
            return message[1] in self.gettext_SettingsSaveState()
